var Helper = {
    ver: 0.1,
    waitModal: null,
    alert: function (c) {
        var a = c || "操作成功";
        var d = "fast_alert_modal_id";
        var b = [];
        b.push('<div id="' + d + '"');
        b.push('<div class="mp-mask mp-mask-alert"></div>');
        b.push('<div class="mp-popup mp-popup-alert" style="left:50%;top:50%;margin:-100px 0 0 -280px;">');
        b.push('<div class="popup-header">');
        b.push('<h2 class="popup-title">系统提示</h2>');
        b.push('<span class="popup-close popup-close-alert"><i class="icon icon-close"></i></span>');
        b.push("</div>");
        b.push('<div class="popup-body">');
        b.push('<div class="operate-result">');
        b.push('<div class="operate-message">' + a + "</div>");
        b.push('<div class="btn-group">');
        b.push('<button type="button" class="btn btn-primary popup-close-alert">确 &nbsp; 定</button>');
        b.push("</div>");
        b.push("</div>");
        b.push("</div>");
        b.push("</div>");
        b.push("</div>");
        $("body").append(b.join(""));
        $(".mp-mask-alert").show();
        $(".mp-mask-alert").height($(document).height());
        $(".mp-popup-alert").slideDown();
        $(".popup-close-alert").click(function () {
            $(".mp-mask-alert").hide();
            $(".mp-popup-alert").hide();
            $("#" + d).remove()
        })
    },
    confirm: function (c, e) {
        var a = c || "确认要退出";
        var d = "fast_confirm_modal_id";
        var b = [];
        b.push('<div id="' + d + '"');
        b.push('<div class="mp-mask mp-mask-confirm"></div>');
        b.push('<div class="mp-popup mp-mask-confirm" style="left:50%;top:50%;margin:-100px 0 0 -280px;">');
        b.push('<div class="popup-header">');
        b.push('<h2 class="popup-title">系统提示</h2>');
        b.push('<span class="popup-close popup-close-event"><i class="icon icon-close"></i></span>');
        b.push("</div>");
        b.push('<div class="popup-body">');
        b.push('<div class="operate-result">');
        b.push('<div class="operate-message">' + a + "</div>");
        b.push('<div class="btn-group">');
        b.push('<button type="button" class="btn btn-primary popup-comfirm-event">确 &nbsp; 定</button>');
        b.push('<button type="button" class="btn btn-default popup-close-event">取 &nbsp; 消</button>');
        b.push("</div>");
        b.push("</div>");
        b.push("</div>");
        b.push("</div>");
        b.push("</div>");
        $("body").append(b.join(""));
        $(".mp-mask-confirm").show();
        $(".mp-popup-confirm").slideDown();
        $(".popup-close-event").click(function () {
            $(".mp-mask-confirm").hide();
            $(".mp-popup").hide();
            $("#" + d).remove()
        });
        $(".popup-comfirm-event").click(function () {
            e();
            $(".mp-mask-confirm").hide();
            $(".mp-popup-confirm").hide();
            $("#" + d).remove()
        })
    },
    confirm_one: function (c, e) {
        var a = c || "确认要退出？";
        var d = "fast_one_modal_id";
        var b = [];
        b.push('<div id="' + d + '"');
        b.push('<div class="mp-mask mp-mask-one"></div>');
        b.push('<div class="mp-popup mp-popup-one" style="left:50%;top:50%;margin:-100px 0 0 -280px;">');
        b.push('<div class="popup-header">');
        b.push('<h2 class="popup-title">系统提示</h2>');
        b.push('<span class="popup-close popup-comfirm-event"><i class="icon icon-close"></i></span>');
        b.push("</div>");
        b.push('<div class="popup-body">');
        b.push('<div class="operate-result">');
        b.push('<div class="operate-message">' + a + "</div>");
        b.push('<div class="btn-group">');
        b.push('<button type="button" class="btn btn-primary popup-comfirm-event">确 &nbsp; 定</button>');
        b.push("</div>");
        b.push("</div>");
        b.push("</div>");
        b.push("</div>");
        b.push("</div>");
        $("body").append(b.join(""));
        $(".mp-mask-one").show();
        $(".mp-mask-one").height($(document).height());
        $(".mp-popup-one").slideDown();
        $(".popup-comfirm-event").click(function () {
            e();
            $(".mp-mask-one").hide();
            $(".mp-popup-one").hide();
            $("#" + d).remove()
        })
    },
    wait: function (d, b) {
        d = d || "请稍候...";
        b = b || "";
        var e = "fast_wait_modal_id";
        var a = [];
        a.push('<div id="' + e + '"');
        a.push('<div class="mp-mask mp-mask-wait"></div>');
        a.push('<div class="mp-popup mp-popup-wait" style="left:50%;top:50%;margin:-100px 0 0 -280px;">');
        a.push('<div class="popup-header">');
        a.push('<h2 class="popup-title">' + d + "</h2>");
        a.push('<span class="popup-close popup-close-event"></span>');
        a.push("</div>");
        a.push('<div class="popup-body">');
        a.push('<div class="operate-result">');
        a.push('<div class="operate-message">' + b + "</div>");
        a.push("</div>");
        a.push("</div>");
        a.push("</div>");
        a.push("</div>");
        $("body").append(a.join(""));
        var c = $("#" + e);
        this.waitModal = c;
        $(".mp-mask-wait").show();
        $(".mp-mask-wait").height($(document).height());
        $(".mp-popup-wait").slideDown()
    },
    closeWait: function () {
        if (this.waitModal) {
            this.waitModal.remove();
            $(".mp-mask-wait").hide();
            $(".mp-popup-wait").hide();
            this.waitModal = null
        }
    },
    show: function (c, f, a, e, d) {
        f = f || "系统提示";
        c = c || "";
        var g = "fast_show_modal_id";
        var b = [];
        a = a || "600px";
        d = d || "-350px";
        e = e || "-400px";
        b.push('<div id="' + g + '"');
        b.push('<div class="mp-mask mp-mask-show"></div>');
        b.push('<div class="mp-content">');
        b.push('<div class="mp-popup mp-popup-show mp-popup-lg" style="left:50%;top:50%;width:820px;margin:' + e + " 0 0 " + d + ';">');
        b.push('<div class="popup-header">');
        b.push('<h2 class="popup-title">' + f + "</h2>");
        b.push('<span class="popup-close popup-close-event"><i class="icon icon-close"></i></span>');
        b.push("</div>");
        b.push('<div class="popup-body" style="height:' + a + '; overflow:auto; ">');
        b.push(c);
        b.push("</div>");
        b.push("</div>");
        b.push("</div>");
        $("body").append(b.join(""));
        $(".mp-mask-show").show();
        $(".mp-mask-show").height($(document).height());
        $(".mp-popup-show").slideDown();
        $(".popup-close-event").click(function () {
            $(".mp-mask-show").hide();
            $(".mp-popup-show").hide();
            $("#" + g).remove()
        })
    },
    checkBlank: function (d, b) {
        var a = $("#" + d);
        var c = $.trim(a.val());
        b = b || "不能为空！";
        if (c == "" || c == undefined) {
            Helper.alert(b);
            a.focus();
            return false
        }
        return true
    },
    getLength: function (a) {
        return a.replace(/[^\x00-\xff]/g, "__").length
    },
    checkLength: function (f, a, d) {
        var c = $("#" + f);
        var e = $.trim(c.val());
        var b = Helper.getLength(e);
        if (b > a) {
            Helper.alert(d);
            c.focus();
            return false
        }
        return true
    },
    checkPositiveInt: function (e, c) {
        var b = $("#" + e);
        var d = $.trim(b.val());
        var a = /^([1-9][0-9]*)$/;
        c = c || "格式不为正整数！";
        if (!a.test(d)) {
            Helper.alert(c);
            b.focus();
            return false
        }
        return true
    },
    checkInt: function (e, c) {
        var b = $("#" + e);
        var d = $.trim(b.val());
        var a = /^\d+$/;
        c = c || "格式不为正整数！";
        if (!a.test(d)) {
            Helper.alert(c);
            b.focus();
            return false
        }
        return true
    },
    checkFloat: function (g, e, a) {
        var d = $("#" + g);
        var f = $.trim(d.val());
        var a = a || 2;
        var c = "^[0-9]+([.][0-9]{" + a + "})?$";
        var b = new RegExp(c, "g");
        e = e || "不为实数！";
        if (!b.test(f)) {
            Helper.alert(e);
            d.focus();
            return false
        }
        return true
    },
    checkFloatNum: function (a, d, e) {
        var e = e || 2;
        var c = "^[0-9]+([.][0-9]{" + e + "})?$";
        var b = new RegExp(c, "g");
        d = d || "不为实数！";
        if (!b.test(a)) {
            Helper.alert(d);
            return false
        }
        return true
    },
    onlyInputInt: function () {
        $(this).val($(this).val().replace(/\D/g, ""))
    },
    getRootPath: function () {
        var a = "";
        if (Helper.getSelfPath().indexOf("www") == -1) {
            a = ""
        }
        //return a
        return ""
    },
    getWebRootPath: function () {
        var a = "";
        if (Helper.getSelfPath().indexOf("www") == -1) {
            a = ""
        }
        //return a;
        return "";
    },
    getSelfPath: function () {
        var a = (window.location + "").split("/");
        return a[0] + "//" + a[2] + "/" + a[3]
    },
    isRepeat: function (a) {
        var c = {};
        for (var b in a) {
            if (c[a[b]]) {
                return a[b]
            }
            c[a[b]] = a[b]
        }
        return null
    },
    isPlaceholderSupported: function () {
        var b = Object.prototype.toString.call(window.operamini) == "[object OperaMini]";
        var a = "placeholder" in document.createElement("input") && !b;
        return a
    },
    md6: function (h, b) {
        var a = (b + "").split("");
        var f = h.length - 1;
        var c = [],
		j,
		d,
		g,
		e;
        for (var i = 0; i < h.length; i++) {
            c.push(h.charAt(i))
        }
        $.each(a, function (l, k) {
            g = parseInt(k, 16);
            e = f - g;
            j = h.slice(g, g + 1);
            d = h.slice(e, e + 1);
            c.splice(g, 1, d);
            c.splice(e, 1, j)
        });
        return c.join("")
    },
    genAuthCode: function (b) {
        var a = Helper.getRootPath() + "/authcode/genAuthCode.do?codeType=" + b + "&random=" + Math.random();
        return a
    },
    getUserEncryCode: function (b) {
        var a = b || "userEncryCode";
        $.ajax({
            url: Helper.getRootPath() + "/user/getEncryCode.do",
            type: "post",
            dataType: "json",
            data: {},
            success: function (c) {
                $("#" + b).val(c.encryCode)
            },
            error: function (e, c, d) {
                Helper.alert("得到用户加密算法失败")
            }
        })
    },
    getForgetEncryCode: function (c, b) {
        var a = c || "userEncryCode";
        $.ajax({
            url: Helper.getRootPath() + "/retrieve/getForgetEncryCode.do",
            type: "post",
            dataType: "json",
            data: {
                key: b
            },
            success: function (d) {
                $("#" + c).val(d.encryCode)
            },
            error: function (f, d, e) {
                Helper.alert("得到用户加密算法失败")
            }
        })
    },
    getUrlParam: function (a) {
        var b = new RegExp("(^|&)" + a + "=([^&]*)(&|$)");
        var c = window.location.search.substr(1).match(b);
        if (c != null) {
            return unescape(c[2])
        }
        return null
    },
    toPercent: function (a) {
        return Math.round(a * 10000) / 100 + "%"
    },
    toRound: function (c, a) {
        var d = a || 6;
        var b = Math.pow(10, d);
        return Math.round(c * b) / b
    },
    toMoney: function (c, e) {
        var h = Helper.toRound(c, e);
        var d = String(h);
        var i = d.split(".");
        var f = i[0];
        var a = i.length > 1 ? "." + i[1] : "";
        var g = /(-?\d+)(\d{3})/;
        while (g.test(f)) {
            f = f.replace(g, "$1,$2")
        }
        var b = f + a;
        return b
    }
};
var flag = 0;
$.ajaxSetup({
    contentType: "application/x-www-form-urlencoded;charset=utf-8",
    cache: false,
    complete: function (c, d) {
        var b = c.getResponseHeader && c.getResponseHeader("sessionStatus");
        var a = c.getResponseHeader && c.getResponseHeader("sessionUserStatus");
        if ("repeat" == a) {
            flag++;
            if (flag == 1) {
                alert("您的账号在另一地点登录，您被迫下线。\n如果这不是您本人的操作，那么您的密码很可能已泄露。\n建议您修改密码")
            }
            location.replace(Helper.getWebRootPath() + "/login.html")
        }
        if ("timeout" == b) {
            flag++;
            if (flag == 1) {
                alert("您的会话已过期 ，请重新登陆")
            }
            location.replace(Helper.getWebRootPath() + "/login.html")
        }
        if ("NOT_Authority" == a) {
            flag++;
            if (flag == 1) {
                alert("您没有该操作的访问权限，已被迫下线！")
            }
            location.replace(Helper.getWebRootPath() + "/login.html")
        }
    }
});
